package com.wyx.Service.impl;

import com.wyx.Dao.BookDao;
import com.wyx.Pojo.Book;
import com.wyx.Service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 图书的相关操作业务层
 */
@Service
public class bookServiceimpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
    public Book selectbyId(Integer id) {
        return bookDao.selectbyId(id);
    }

    @Override
    public List<Book> selectall() {
        return bookDao.selectall();
    }

    @Override
    public Boolean update(Book book) {
        return bookDao.update(book)>0;
    }

    @Override
    public Boolean delete(Integer id) {
        return bookDao.delete(id)>0;
    }

    @Override
    public Boolean add(Book book) {
        if ("".equals(book.getName())||book.getName()==null){
            return false;
        }
        if ("".equals(book.getWritter())||book.getWritter()==null){
            return false;
        }
        if ("".equals(book.getType())||book.getType()==null){
            return false;
        }
        return bookDao.add(book)>0;
    }

    @Override
    public List<Book> getPage(String name, String writter ,int page, int  pagesizes) {
        name="%"+name+"%";
        writter="%"+writter+"%";
        List<Book> page1 = bookDao.getPage(name,writter,(page-1)*pagesizes,pagesizes);
        return page1;
    }

    @Override
    public Integer getCount(String name,String writter) {
        name="%"+name+"%";
        writter="%"+writter+"%";
        return bookDao.getCount(name,writter);
    }
}
